package clientproject.window;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;

public class ClientWindow
{

	private JFrame		frame;
	private JTextField	textField;
	private JTable		chatTable;
	private JButton		button;
	private JScrollPane	scrollPane_1;
	private JTable		memberTable;

	/**
	 * Create the application.
	 */
	public ClientWindow()
	{
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize()
	{
		frame = new JFrame();
		frame.setBounds(100, 100, 822, 460);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);

		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(12, 10, 648, 371);
		frame.getContentPane().add(scrollPane);

		TableCellRenderer renderer = new MyTableCellRenderer();

		chatTable = new JTable();
		chatTable.setEnabled(false);
		chatTable.setRowSelectionAllowed(false);
		chatTable.setShowGrid(false);
		chatTable.setShowVerticalLines(false);
		chatTable.setShowHorizontalLines(false);
		chatTable.setModel(new DefaultTableModel(new Object[][] {}, new String[] { "\uB300\uD654\uCC3D" }));
		try
		{
			chatTable.setDefaultRenderer(Class.forName("java.lang.Object"), renderer);
		} catch (ClassNotFoundException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		scrollPane.setViewportView(chatTable);

		textField = new JTextField();
		textField.setBounds(12, 391, 687, 21);
		frame.getContentPane().add(textField);
		textField.setColumns(10);

		button = new JButton("전송");

		button.setBounds(697, 390, 97, 23);
		frame.getContentPane().add(button);

		scrollPane_1 = new JScrollPane();
		scrollPane_1.setBounds(672, 10, 122, 371);
		frame.getContentPane().add(scrollPane_1);

		memberTable = new JTable();
		memberTable.setModel(new DefaultTableModel(new Object[][] {}, new String[] { "\uC811\uC18D\uC790" }));
		scrollPane_1.setViewportView(memberTable);

		frame.setVisible(true);
	}

	/**
	 * @return the chatTable
	 */
	public JTable getTable()
	{
		return chatTable;
	}

	/**
	 * @param chatTable
	 *            the chatTable to set
	 */
	public void setTable(JTable table)
	{
		this.chatTable = table;
	}

	/**
	 * @return the textField
	 */
	public JTextField getTextField()
	{
		return textField;
	}

	/**
	 * @param textField
	 *            the textField to set
	 */
	public void setTextField(JTextField textField)
	{
		this.textField = textField;
	}

	/**
	 * @return the button
	 */
	public JButton getButton()
	{
		return button;
	}

	/**
	 * @param button
	 *            the button to set
	 */
	public void setButton(JButton button)
	{
		this.button = button;
	}

	/**
	 * @return the memberTable
	 */
	public JTable getMemberTable()
	{
		return memberTable;
	}

	/**
	 * @param memberTable
	 *            the memberTable to set
	 */
	public void setMemberTable(JTable memberTable)
	{
		this.memberTable = memberTable;
	}

	/**
	 * Cell마다 글자색을 다르게해주기위한 Renderer
	 * 
	 * 조건은 내용의 글
	 * @author 201011832 김남중
	 *
	 */
	@SuppressWarnings("serial")
	public class MyTableCellRenderer extends DefaultTableCellRenderer
	{
		@Override
		public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row,
				int column)
		{
			Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
			if (!isSelected)
			{
				if (table.getValueAt(row, 0).toString().contains("과장"))
					cell.setForeground(Color.red);
				else
					cell.setForeground(Color.BLACK);

			}
			return cell;
		}
	}

}
